<template>
  <div>
    <el-dialog
      class="my_dialog"
      v-bind="$attrs"
      v-on="$listeners"
      v-draggable
      width="600px"
      :visible="visible"
      @open="onOpen"
      @close="onClose"
      :title="title"
      :close-on-click-modal="false"
    >
      <el-form
        ref="elForm"
        :model="formData"
        :rules="rules"
        size="medium"
        label-width="100px"
      >
        <el-form-item label="表类别" prop="tableTypeId">
          <el-select
            v-model="formData.tableTypeId"
            placeholder="请选择表类别"
            clearable
            :style="{ width: '100%' }"
          >
            <el-option
              v-for="(item, index) in inOutFlagOptions"
              :key="index"
              :label="item.dictLabel"
              :value="Number(item.dictValue)"
              :disabled="item.disabled"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="表名" prop="tableName">
          <el-input
            v-model="formData.tableName"
            placeholder="请输入表名"
            clearable
            :style="{ width: '100%' }"
          >
          </el-input>
        </el-form-item>
        <el-form-item label="表說明" prop="tableDesc">
          <el-input
            v-model="formData.tableDesc"
            placeholder="请输入表說明"
            clearable
            :style="{ width: '100%' }"
          >
          </el-input>
        </el-form-item>
        <el-form-item
          label="表英文描述
"
          prop="tableDescEN"
        >
          <el-input
            v-model="formData.tableDescEN"
            placeholder="请输入表英文描述"
            clearable
            :style="{ width: '100%' }"
          >
          </el-input>
        </el-form-item>
        <el-form-item label="字段名称" prop="columnName">
          <el-input
            v-model="formData.columnName"
            placeholder="请输入字段名称"
            clearable
            :style="{ width: '100%' }"
          >
          </el-input>
        </el-form-item>
        <el-form-item label="字段描述" prop="columnDesc">
          <el-input
            v-model="formData.columnDesc"
            placeholder="请输入字段描述"
            clearable
            :style="{ width: '100%' }"
          >
          </el-input>
        </el-form-item>
        <el-form-item label="字段英文描述" prop="columnDescEN">
          <el-input
            v-model="formData.columnDescEN"
            placeholder="请输入字段英文描述"
            clearable
            :style="{ width: '100%' }"
          >
          </el-input>
        </el-form-item>
        <el-form-item label="字段类型" prop="columnType">
          <el-input
            v-model="formData.columnType"
            placeholder="请输入字段类型"
            clearable
            :style="{ width: '100%' }"
          >
          </el-input>
        </el-form-item>
        <el-form-item
          label="字段长度
"
          prop="columnLength"
        >
          <el-input
            v-model="formData.columnLength"
            placeholder="请输入字段长度"
            clearable
            :style="{ width: '100%' }"
          >
          </el-input>
        </el-form-item>
        <el-form-item label="默认值" prop="columnDefault">
          <el-input
            v-model="formData.columnDefault"
            placeholder="请输入默认值"
            clearable
            :style="{ width: '100%' }"
          >
          </el-input>
        </el-form-item>
      </el-form>
      <div slot="footer">
        <el-button @click="onClose">取消</el-button>
        <el-button type="primary" @click="handleConfirm">确定</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
export default {
  inheritAttrs: false,
  components: {},
  props: ["title", "visible", "item"],
  data() {
    return {
      formData: {
        tableTypeId:0,
        tableName:"",
        tableDesc:"",
        tableDescEN:"",
        columnName:"",
        columnDesc:"",
        columnDescEN:"",
        columnType:"",
        columnLength:"",
        columnDefault:"NULL"
      },
      rules: {
        tableName: [
          {
            required: true,
            message: "请输入表名",
            trigger: "blur",
          },
        ],
        tableTypeId: [
          {
            required: true,
            message: "请选择表类别",
            trigger: "change",
          },
        ],
      },
      inOutFlagOptions: [],
    };
  },
  computed: {},
  watch: {},
  created() {
    this.getDictText();
  },
  mounted() {},
  methods: {
    getDictText() {
      this.getDicts("sys_normal_disable").then((res) => {
        console.log(res.data);
        if (res.data != null) {
          this.inOutFlagOptions = res.data;
        }
      });
    },
    onOpen() {
      this.$nextTick(() => {
        if (this.item) {
          this.formData = JSON.parse(JSON.stringify(this.item));
          console.log(this.formData)
        }
      });
    },
    onClose() {
      this.$refs["elForm"].resetFields();
      this.close();
    },
    close() {
      this.$emit("update:visible", false);
    },
    handleConfirm() {
      let form = JSON.parse(JSON.stringify(this.formData));
      console.log(form);
      this.$refs["elForm"].validate((valid) => {
        if (!valid) return;
        this.$emit("Ok", form);
        this.close();
      });
    },
  },
};
</script>
<style>
</style>
